package com.heima.ssm.service.impl;

import com.heima.ssm.dao.IRoleDao;
import com.heima.ssm.pojo.Permission;
import com.heima.ssm.pojo.Role;
import com.heima.ssm.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author Penguin
 * @create Date 2021/5/6  Time 19:37
 */

@Service
@Transactional
public class RoleServiceImpl implements IRoleService {

    @Autowired
    private IRoleDao roleDao;

    @Override
    public List<Role> findAll() {
        return roleDao.findAll();
    }

    @Override
    public void add(Role role) {
        roleDao.add(role);
    }

    @Override
    public Role findById(int roleId) {
        return roleDao.findById(roleId);
    }

    @Override
    public List<Permission> findOtherPermissionByRoleId(int roleId) {
        return roleDao.findOtherPermissionByRoleId(roleId);
    }

    @Override
    public void addPermissionToRole(int roleId, int[] permissionIds) {
        for (int permissionId : permissionIds) {
            roleDao.addPermissionToRole(roleId,permissionId);
        }
    }
}
